package project;
import java.io.IOException;
import java.util.Vector;
import java.util.Random;


public class Game {
	Vector Animals;

	public Game(){
	Animals = new Vector(0);
	}
	public void addAnimal(Animal A){
		Animals.addElement(A);
	}
	public void removeAnimal(String A){
		for(int i = 0;i<Animals.capacity();i++){
			if(((Animal) Animals.elementAt(i)).getName() ==A){
				Animals.removeElementAt(i);
				break;
			}
		}
	}
	public StringBuffer printAnimals(){
		StringBuffer out = new StringBuffer();
		for(int i =0;i<Animals.capacity();i++){
			out.append("Animal " + i + " = " + ((Animal) Animals.elementAt(i)).getName());
		}
		return out;
	}
	/*public void moveAnimals(){
		StringBuffer out = new StringBuffer();
		Animal a;
		Random generator = new Random();
		boolean done = false;
		int ran = generator.nextInt();
		while(ran<1){
			ran = generator.nextInt();
		}
		out.append("ran = " + ran);
		ran = ran % 8;
		while(ran<0){
			ran = generator.nextInt();
			ran = ran%8;
		}
		for(int i=0;i<Animals.capacity();i++){
		a = (Animal) Animals.elementAt(i);
		out.append("ran = " + ran);
		
		while(!done){
			if(ran ==0){
				a.moveUp();
				out.append("up");
			}
			if(ran ==1){
				a.moveUpRight();
				out.append("upright");
			}
			if(ran ==2){
				a.moveRight();
				out.append("right");
			}
			if(ran ==3){
				a.moveDownRight();
				out.append("downright");
			}
			if(ran ==4){
				out.append("down");
				a.moveDown();
			}
			if(ran ==5){
				a.moveDownLeft();
				out.append("downleft");
			}
			if(ran ==6){
				a.moveLeft();
				out.append("left");
			}
			if(ran ==7){
				a.moveUpLeft();
				out.append("upleft");
			}
			if(a.getXpos()<0 || a.getYpos()<0||a.getXpos()>19||a.getYpos()>19){
				out.append("eeek");
				out.append("ran = " + ran);
				if(ran ==0){
					out.append("down2");
					a.moveDown();
				}
				if(ran ==1){
					out.append("downleft2");
					a.moveDownLeft();
				}
				if(ran ==2){
					out.append("left2");
					a.moveLeft();
				}
				if(ran ==3){
					out.append("upleft2");
					a.moveUpLeft();
				}
				if(ran ==4){
					out.append("up2");
					a.moveUp();
				}
				if(ran ==5){
					out.append("upright2");
					a.moveUpRight();
				}
				if(ran ==6){
					out.append("right2");
					a.moveRight();
				}
				if(ran ==7){
					out.append("downright2");
					a.moveDownRight();
				}
				ran = generator.nextInt(); 
				
			}
			done = true;
			
		}
		out.append("xpos = " + a.getXpos() + " ypos = " + a.getYpos());
		Animals.setElementAt(a,i);
		done = false;
		ran = generator.nextInt();
		int q = generator.nextInt();
		out.append("ran = " + ran);
		ran = ran % 8;
		while(ran<0){
			ran = generator.nextInt();
			ran = ran % 8;
		}
		}
		
	}
	*/
	/*public StringBuffer enterBattleMode(String name1,String name2){
		StringBuffer out = new StringBuffer();
		out.append("*** ENTERING BATTLE MODE ***");
		out.append("-- the two competitors stand outside the ring and perform their riturals");
		out.append("-- " + name1 + " streches arrogantly as he stares into " + name2 + "'s eyes");
		out.append("-- " + name2 + " chackles demonically with a cold look of power about him");
		out.append("-- the bell rings and the two competitors step into the ring" );
		out.append("-- the two combatants bow ");
		out.append("-- the referee enters the ring");
		out.append("-- Referee: ok now i want a good clean fight!!! no low blows " +
				"and no shots to the back of the head \n-- "
				+ name1 + ": ok! \n-- " + name2 + ": alright!\n"    );
		out.append("-- Referee: OK!!! LETS GET IT ON!!!");
	
		return out;
	}
	*/
	public StringBuffer attackAnimals(Animal a,Animal b){
		StringBuffer out = new StringBuffer();
		String name1 = a.getName();
		String name2 = b.getName();
		Random generator = new Random();
		int p,q,attackval1;
		boolean n = false,m = false;
		Vector Aattackts = new Vector(0);
		Vector Battacks = new Vector(0);
		
		p = generator.nextInt();
		p = p%4;
		
		while(p<0){
			p = generator.nextInt();
			p = p% 4;
		}
		out.append(name1 + " prepares to attack\n");
		if(p == 0){
			out.append(name1 + " tries to use his dexterity\n");
		}else if(p == 1){
			out.append(name1 + " tries to use his speed\n");
		}else if(p == 2){
			out.append(name1 + " tries to use his strength\n");
		}else{
			out.append(name1 + " tries to use his intelligence\n");
		}
		
		attackval1 = a.getRandomStat(p);
		q = generator.nextInt();
		q = q%4;
		while(q<0){
			q = generator.nextInt();
			q = q% 4;
		}
		
		if(q == 0){
			out.append(name2 + " tries to block dexterity\n");
		}else if(q == 1){
			out.append(name2 + " tries to block speed\n");
		}else if(q == 2){
			out.append(name2 + " tries to block strength\n");
		}else{
			out.append(name2 + " tries to block intelligence\n");
		}
		if(p == q){
			out.append(name2 + " blocked " + name1 + "'s attack\n");
		}else{
			b.decreaseHP(attackval1);
			out.append(name2 + " takes " + attackval1 + " damage to his health points\n");
			out.append(name2 + " staggers from the force of the blow\n");
		}
		return out;
	
	}
	public StringBuffer fightAnimals(String name1,String name2){
		StringBuffer out = new StringBuffer();
		out.append("name1 = " + name1 + "/t name2 = " + name2);
		this.printAnimals();
		out.append("\n");
		Random generator = new Random();
		int p,q,attackval1;
		Animal a = null,b = null;
		boolean n = false,m = false;
		Vector Aattackts = new Vector(0);
		Vector Battacks = new Vector(0);
		
		for(int i=0;i<Animals.capacity();i++){
			if(name1.equals( ((Animal) Animals.elementAt(i)).getName())){
				a = (Animal) Animals.elementAt(i);
				n = true;
			}
		}
		for(int i=0;i<Animals.capacity();i++){
			if(name2.equals(((Animal) Animals.elementAt(i)).getName())){
				b = (Animal) Animals.elementAt(i);
				m = true;
			}
		}
		if(n!=true || m != true){
			//out.append("\nsorry but those two animals are not in the pen");
		}else{
		//		this.enterBattleMode(name1,name2);
				
			while(a.getHP()>0 && b.getHP()>0){
				out.append("a.getHP = " + a.getHP() + " b.getHP = " + b.getHP());
				
				this.attackAnimals(a,b);
				this.attackAnimals(b,a);
			}
		}
		return out;
	}
	//public Animal(int sp,int st,int d,int inte,int a,String nme,String pwn){
	/*public StringBuffer makeAnimal(String name, String owner, int choice){
		StringBuffer out = new StringBuffer();
		Animal a = null;
		int points = 15;
		
		if(choice == 1){
			a = new Ape(3,0,0,0,name,owner);
		}
		if(choice == 2){
			a = new Ape(0,3,0,0,name,owner);
		}
		if(choice == 3){
			a = new Ape(0,0,3,0,name,owner);
		}
		out.append(" you have 15 attribute points to distribute to the attributs you would like " +
				"or you could us your points to increase your health points by 1");
		out.append("please enter what you would like to do");
		while(points > 0){
			out.append("you have " + points + "attribute points remaining");
			out.append("1: increase dexterity");
			out.append("2: increase speed");
			out.append("3: increase strength");
			out.append("4: increase intelligence");
			out.append("5: increase hp");
			
			out.append("choice = " + choice);
			switch(choice){
			case 1:
				out.append("dexterity increased!");
				a.incDex();
				points--;
				break;
			case 2:
				out.append("speed increased!");
				a.incSpeed();
				points--;
				break;
			case 3:
				out.append("strength increased!");
				a.incStrength();
				points--;
				break;
			case 4:
				out.append("intelligence increased!");
				a.incIntelligence();
				points--;
				break;
			case 5:
				out.append("hp increased!");
				a.increaseHP();
				points--;
				break;
				
			}out.append("too far");
		}
		out.append("your animal " + a.name + " has been created");
		Animals.addElement(a);
		
		return out;
		
	}*/
}
